var PublishMemberFin = {
	account : null,
	load : function () {
		var qs =  new QueryString();
		PublishMemberFin.account = qs.get("customerAccount");
		if (!PublishMemberFin.account) {
			PublishMemberFin.account = getManagerUser().Account;
		}
		 
		Ext.QuickTips.init();
		this.eventRegister();
 
		PublishMemberFin.createGrid(); //建立 Ext table
		
		waitShow();
		Ext.Ajax.request ({
			url : "/ad/sys/com/control/publish/UserService.php?action=queryAllPayToUserDateByAccount&managerAccount="+PublishMemberFin.account,
			callback : function (op, sc, resp) {
				var obj =  resp.responseText.toJSON();	
//				var notify = new Ext.XTemplate(
//		            '<tpl for=".">',
//		               '<li>{#}.<span class="date">{CreateTime:this.fn}</span><span class="announce">{Content}</span></li>',
//		            '</tpl>',
//		            {
//		            	fn : function (time) {
//		            		return time.toDateString();
//		            	}
//		            }
//		        );
//		    
//		        var pay = new Ext.XTemplate(
//		            '<tpl for=".">',
//		               '<li>{#}.<span class="date">{createtime:this.fn}</span>	<span class="currency">{pay}(元)</span></li>',
//		            '</tpl>',
//		            {
//			            fn : function (time) {
//			            	return time.toDateString("mm月dd日");
//			            }
//		            }
//		        );
//		        notify.overwrite("notify", obj.notify);
//				pay.overwrite("pay", obj.pay);
//				
				waitHide();
		       
			}
		})  
		
	},
	
	eventRegister : function () {
//	    Ext.get("btnQuery").on('click',this.query);  //確認,新增使用者	
	}, 
	
	query : function () {
//		var name = Ext.getDom("name").value;
		
		PublishMemberFin.store.reload({
			params:{
				start:0,
				limit:20,
//				name : name,
			}
		});  
		
	},
	
	createGrid : function () {
	 	 PublishMemberFin.store = new Ext.data.JsonStore ({
	 		url : "/ad/sys/com/control/publish/UserService.php?action=queryAllPayToUserDateByAccount&managerAccount="+PublishMemberFin.account,
			root : "row", 
			remoteSort: false,
			totalProperty: 'count',
			fields : ["PayId", "PayMoney", "PayDate","Statue"]
		});
		 
		PublishMemberFin.grid =
			 new Aitch.ext.ETable({
				renderTo : "grid",
				columns : [ 
				        { name:'PayId',   dataIndex:'PayId',   header:'付款編號', type:'string',  sortable:true, width:80, editor:textFieldEditor },
						{ name:'PayMoney', dataIndex:'PayMoney', header:'給付金額', type:'string',  sortable:true, width:50, editor:genderFieldEditor, renderer:genderRenderer },
						{ name:'PayDate',    dataIndex:'PayDate',    header:'給付日期', type:'date',    sortable:true, width:80, editor:dobFieldEditor,    renderer:Ext.util.Format.dateRenderer('Y年m月d日')},
						{ name:'Status',    dataIndex:'Status',    header:'已付款', type:'string',    sortable:false, width:80,   editor:dobFieldEditor,  renderer:checkRenderer},
					],
				root:"row",
				gridPanelTitle : '付款資訊',
				store :  PublishMemberFin.store,
				gridPanelWidth:'100%',
				gridPanelHeight:280,
//				pageSize:5,
				enableRowEditor:false,
				api:{
					create: 'data_writer_test.php?op=create',
					read:   'data_writer_test.php?op=read',
					update: 'data_writer_test.php?op=update',
					destroy:'data_writer_test.php?op=destroy'
				}
			});
//			PublishMemberFin.grid =new Ext.grid.EditorGridPanel({
//			renderTo : "grid",
//			store :  PublishMemberFin.store,
//			height: 450,
//		    //autoWidth: true,
//			loadMask : true,
//			viewConfig : {
//				forceFit : true 
//			},
//			columns : [ 
//				{header : "付款編號" ,dataIndex : "PayId", width :200,sortable : true ,editor: new Ext.form.TextField()},
//				{header : "給付金額", dataIndex : "PayMoney",width :150, sortable : false,editor: new Ext.form.TextField() } ,
//				{header : "給付日期", dataIndex : "PayDate",width :100, sortable : true , type:'date',  editor:dobFieldEditor,    renderer:Ext.util.Format.dateRenderer('Y年m月d日')},
//				{header : "已付款", dataIndex : "PayId",width :55, sortable : true ,editor: false,renderer:function(value, p , record){return "<input name='status' type='checkbox'/>";}},
//			],
//			
//			bbar : new Ext.PagingToolbar({
//				pageSize :20,
//				store : PublishMemberFin.store,
//				displayInfo : true,
//				displayMsg : "顯示第 {0} 筆到 {1} 筆紀錄,共 {2} 筆紀錄",
//				emptyMsg : "沒有紀錄" 
//			})
//		});	
		
		PublishMemberFin.store.load({
			params:{
				start:0,
				limit:20
			}
		});    
		
		
	}
	 
};

Ext.onReady(function() {
	PublishMemberFin.load();
	Ext.fly("search").on("click",function(){
		var u = new PublishMemberFin.store.recordType({
			PayId : '',
			PayMoney: '',
			PayDate : ''}
		);
		PublishMemberFin.store.insert(0, u);
		PublishMemberFin.grid.startEditing(0);
		
		});

});